package com.orange.modules.dao;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.AuthExpertPowerMap;

@Repository
public class AuthExpertPowerMapRepository {

	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthExpertPowerMapDao authExpertPowerMapDao;
	
	/**
	 * 
	 * @param aepm
	 * @throws SQLException
	 */
	public void insertAuthExpertPowerMap(AuthExpertPowerMap aepm) throws SQLException{
		authExpertPowerMapDao.save(aepm);
	}
	
	/**
	 * 查询该专家被指定了哪几项
	 * @param powerType
	 * @param expertId
	 * @return
	 * @throws SQLException
	 */
	public List<AuthExpertPowerMap> queryOnceByExpertId(String powerType,String expertId) throws SQLException{
		String sql = "SELECT t.p_id as pid,t.s_expert_id as expertId,"
				+ "t.power_type as powerType,t.power_value as powerValue,"
				+ "t.s_create_time as createTime,t.s_sid as sid,"
				+ "i.s_content as powerName,a.s_school_name as schoolName,"
				+ "a.s_major as schoolMajor from t_auth_expert_power_map t "
				+ "LEFT JOIN t_auth_school a on t.s_sid = a.p_id "
				+ "LEFT JOIN t_auth_item i ON t.power_value = i.p_id where 1=1";
		if(powerType==null && StringUtils.isNotBlank(powerType)){
			sql+=" t.power_type = '"+powerType+"'"; 
		}
		if(expertId==null && StringUtils.isNotBlank(expertId)){
			sql+="AND t.s_expert_id = '"+expertId+"'";
		}
		List<AuthExpertPowerMap> list = dbHelper.getBeanList(sql, AuthExpertPowerMap.class);
		return list;
	}
}
